<template>
	<view class="content">
		<u-navbar bgColor="#fff" :placeholder="true" :fixed="true" @leftClick="$back" title="关联订单" titleStyle="{'color': '#000'}">
			
		</u-navbar>
		<view class="orbox">
			<view class="empytView" v-if="!list.total">
				<image :src="'/images/kong.png' | formatImgUrl" mode="widthFix" />
				<!-- <view>- 空列表 -</view> -->
			</view>

			<view class="orli" v-for="item in rowList">

				<view @click="toBack">

					<view class="shbox">
						<image :src="item.order.writer.pic | formatImgUrl" class="head" mode=""></image>
						<view class="shou">
							{{item.order.writer.username}}
						</view>
						<view class="tuitxt">

							<text v-if="item.refs_status==0" class="status3">申请中</text>
							<text v-if="item.refs_status==1" class="status3">已退款</text>
							<text v-if="item.refs_status==2" class="status3" style="color: #999;">拒绝退款</text>
							<text v-if="item.refs_status==3" class="status3" style="color: #999;">取消退款</text>
						</view>
					</view>

					<view class="jjbox">
						<image :src="'/images/jj.png' | formatImgUrl" class="kpic" mode=""></image>
						<view class="jtxt">
							{{item.order.c_title}}
						</view>
					</view>
					<view class="dbox">
						<view class="dtxt display-flex">
							{{item.order.c_desc}}<text>| 共{{item.order.ref_num}}单</text><text>| 共{{item.order.num || ''}}{{item.order.c_word_count || ''}}</text>
						</view>
						<view class="gong">
							共计支付
							<text class="active">{{item.cv_price?(Number(item.price - item.cv_price).toFixed(0)):Number(item.price).toFixed(0)}}</text>
							币
						</view>
					</view>
					<view class="order-tip order-tip2 display-flex just-between" v-if="item.refs_status==0 || item.refs_status==1">
						<view class="order-tip-left display-flex">
							<image :src="'/images/ordericon01.png' | formatImgUrl" mode="aspectFit"></image>
							<text class="status-txt">{{item.ref_status == 1 ? '部分退款' : '全部退款'}}</text>
							<text class="status-desc">退还 {{Number(item.price).toFixed(0)}}粮币 至账户余额</text>
						</view>
					</view>
					<view class="order-tip order-tip2 display-flex just-between" v-if="item.refs_status==2" @tap="showReason=true">
						<view class="order-tip-left display-flex">
							<image :src="'/images/ordericon01.png' | formatImgUrl" mode="aspectFit"></image>
							<text class="status-txt">拒绝退款</text>
							<text class="status-desc">您的退款申请已被驳回</text>
						</view>
					</view>

					<view class="buttons display-flex">

						<!-- <view class="button-item button1">
							删除记录
						</view> -->
						<view class="button-item button2">
							查看详情
						</view>
					</view>
				</view>

			</view>


			<!-- <view class="nomore" v-if="rowList.length && list.current_page == list.last_page">
				没有更多了~
			</view> -->

		</view>


		<!-- 删除记录 -->
		<u-popup mode="center" :show="showPop" @close="closeOrder">
			<view class="mask">
				<view class="matitle">
					是否确定取消该订单
				</view>
				<view class="matxt">
					此操作不可更改
				</view>
				<view class="quque">
					<view class="quli" @click="showPop = false">
						取消
					</view>
					<view class="quli quactive" @click="goToindex(currentItem)">
						确定
					</view>
				</view>
			</view>
		</u-popup>
		
		<u-popup mode="center" :show="showReason" @close="showReason=false">
			<view class="reason-pop">
				<view class="reason-title">
					退款申请已拒绝
				</view>
				<view class="reason-user display-flex">
					
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				page: 1,
				status: '',
				list: {},
				rowList: [],

				showPop: false,
				currentItem: {},
				oid: '',
				rowList: [],
				showReason: false
			}
		},
		onLoad(e) {
			if (e.oid) {
				this.oid = e.oid
				this.getList()
			}
		},
		// 上拉加载
		onReachBottom() {
			if (this.list.current_page < this.list.last_page) {
				this.page++; // 页数加一，加载下一页数据
				this.getList();
			}
		},
		methods: {
			toBack(){
				uni.navigateBack()
			},
			getDateStr(mss, type) {
				var days = parseInt(mss / 86400);
				var hours = parseInt((mss - (days * 86400)) / 3600);
				var minutes = parseInt((mss - (days * 86400) - (hours * 3600)) / 60);
				var seconds = mss - (days * 86400) - (hours * 3600) - (minutes * 60)

				if (type == 0) {
					return days;
				}
				if (type == 1) {
					return hours;
				}
				if (type == 2) {
					return minutes;
				}
				if (type == 3) {
					return seconds;
				}

			},
			lookOrder(item) {

				var url = ''
				if (this.$db.get('userInfo').membe_id == item.uid) {
					url = '/pages/user/orderdetail?id=' + item.id
				}
				if (this.$db.get('userInfo').membe_id == item.writer_uid) {
					url = '/pages/my/connect?id=' + item.id
				}

				uni.navigateTo({
					url: url
				})
			},
			getList() {
				this.$api.default.request('order/lookRefOrder', {
					oid: this.oid,
					page: this.page
				}).then((res) => {
					if (res.code == 1) {
						this.list = res.data
						if (res.data.current_page > 1) {
							res.data.data.forEach((item) => {
								this.rowList.push(item)
							})
						} else {
							this.rowList = res.data.data
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	// 10.16新增
	.status-box {
		white-space: nowrap;
		padding-bottom: 24rpx;
		font-family: Source Han Sans CN;
		font-size: 14px;
		color: #999999;

		text {
			margin-right: 24rpx;
		}

		.current {
			font-weight: bold;
			color: #3D3D3D;
		}
	}

	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {
		.topli {
			background-color: #ffffff;
			height: 74rpx;
			border-bottom: 1px solid rgba(153, 153, 153, 0.1);
			display: flex;
			align-items: center;
			justify-content: center;

			.toptxt {
				width: 50%;
				text-align: center;
				font-size: 24rpx;
				color: #999999;
			}

			.active {
				font-weight: bold;
				color: #3d3d3d;
			}
		}

		.orbox {
			padding: 20rpx 30rpx;

			.ortop {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-bottom: 20rpx;

				.ortitle {
					font-size: 32rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
				}

				.oryou {
					display: flex;
					align-items: center;
					justify-content: flex-end;

					.orpic {
						width: 32rpx;
						height: 32rpx;
					}

					.saitxt {
						padding-left: 32rpx;
						font-size: 24rpx;
						font-weight: normal;
						text-align: right;
						letter-spacing: 0em;
						color: #999999;
					}
				}
			}

			.orli {
				padding: 20rpx 20rpx 16rpx;
				border-radius: 8px;
				opacity: 1;
				background: #FFFFFF;
				margin-bottom: 20rpx;

				.shbox {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-bottom: 26rpx;

					.head {
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
						flex-shrink: 0;
					}

					.shou {
						flex-grow: 1;
						padding: 0 12rpx;
						font-size: 24rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #3D3D3D;
					}

					.taitxt {
						font-size: 20rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
						flex-shrink: 0;
					}

					.tuitxt {
						font-size: 20rpx;
						color: #999999;

						.status1 {
							color: #ED3232;
						}

						.status2 {
							color: #3D3D3D;
						}

						.status3 {
							color: #45C4B0;
						}
					}

					.lv {
						color: #45C4B0;
						font-weight: bold;
					}
				}

				.jjbox {
					display: flex;
					align-items: center;

					.kpic {
						width: 32rpx;
						height: 32rpx;
					}

					.jtxt {
						font-size: 28rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
						padding-left: 12rpx;
					}
				}

				.dbox {
					display: flex;
					align-items: flex-end;
					justify-content: space-between;

					.dtxt {
						font-size: 20rpx;
						color: #3D3D3D;

						text {
							padding-left: 8rpx;
							font-size: 20rpx;
							color: #999999;
						}
					}

					.gong {
						font-size: 20rpx;
						color: #999999;

						text {
							font-size: 36rpx;
							color: #3D3D3D;
							padding: 0 8rpx;
							font-weight: bold;
						}

						.active {
							color: #3D3D3D;
						}

						.lv {
							color: #45C4B0;
						}
					}
				}
			}
		}

		.mask {
			background: #F2F5F2;
			border-top-left-radius: 8px;
			border-top-right-radius: 8px;
			overflow: hidden;

			.mabox {
				margin-bottom: 20rpx;

				.matop {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 40rpx 50rpx;
					border-bottom: 1px solid rgba(153, 153, 153, 0.1);
					background-color: #ffffff;

					.mapic {
						width: 40rpx;
						height: 40rpx;
						flex-shrink: 0;
					}

					.matxt {
						flex-grow: 1;
						font-size: 28rpx;
						padding: 0 16rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
					}
				}
			}

			.qubox {
				line-height: 120rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
				height: 120rpx;
				opacity: 1;
				background: #FFFFFF;
			}
		}
	}

	.order-tip {
		padding: 16rpx 25rpx;
		border-radius: 4px;
		margin: 20rpx 0;

		image {
			width: 24rpx;
			height: 24rpx;
		}

		.status-txt {
			font-family: Source Han Sans CN;
			font-size: 10px;
			font-weight: bold;
			margin: 0 8rpx;
		}

		.order-tip-right,
		.status-desc {
			font-family: Source Han Sans CN;
			font-size: 10px;
		}
	}

	// 待接单 进行中
	.order-tip1 {
		background: rgba(69, 196, 176, 0.15);

		.status-txt {
			color: #45C4B0;
		}

		.order-tip-right,
		.status-desc {
			color: #45C4B0;
		}
	}

	// 待处理 已退款
	.order-tip2 {
		background: #F2F5F2;

		.status-txt {
			color: #3D3D3D;
		}

		.order-tip-right,
		.status-desc {
			color: #3D3D3D;
		}
	}

	.buttons {
		justify-content: flex-end;

		.button-item {
			width: 62px;
			height: 20px;
			border-radius: 94px;
			padding: 3px 10px;
			font-family: Source Han Sans CN;
			font-size: 10px;
			margin-left: 16rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.button1 {
			background: #F2F5F2;
			color: #999999;
		}

		.button2 {
			background: rgba(69, 196, 176, 0.15);
			color: #45C4B0;
		}
	}

	.mask {
		background-color: #ffffff;
		width: 534rpx;
		border-radius: 8px;
		padding-top: 48rpx;

		.matitle {
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
			letter-spacing: 0em;
			color: #3D3D3D;
			padding-bottom: 6rpx;
			line-height: 46rpx;
		}

		.matxt {
			font-size: 24rpx;
			font-weight: normal;
			text-align: center;
			letter-spacing: 0em;
			color: #999999;
			line-height: 34rpx;
			padding-bottom: 50rpx;
		}

		.quque {
			display: flex;
			align-items: center;
			border-top: 1px solid rgba(153, 153, 153, 0.1);

			.quli {
				width: 50%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				font-weight: normal;
				letter-spacing: 0em;
				color: #3D3D3D;
			}

			.quactive {
				background: rgba(69, 196, 176, 0.05);
			}
		}
	}
	
	/deep/.scoped-ref view{
		display: flex;
		align-items: center;
	}
</style>